package com.caishi.lkx.order.model;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.zzw.common.entity.impl.BaseEntity;
import com.caishi.lkx.order.ienum.status.OrderStatus;
import com.caishi.lkx.order.ienum.type.OrderType;
import lombok.*;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author by keray
 * date:2019/7/29 10:11
 * 系统订单
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("or_order")
public class OrderModel extends BaseEntity<OrderModel> {

    /// 所属平台Id
    private Long groupId;
    /**
     * 订单金额（分）
     */
    private Long price;

    private OrderType type;

    private OrderStatus orderStatus;

    // 订单拥有者
    private String userId;

    /**
     * 有效期至
     */
    private LocalDateTime expiredDate;


    /**
     * 备注
     */
    private String remark;
    private String recommendId;
    @TableField(exist = false)
    private String recommendName;

    public String getOrderSn() {
        return this.getId();
    }

    public Boolean getHavePay() {
        return orderStatus == OrderStatus.waitSend ||
                orderStatus == OrderStatus.waitSign ||
                orderStatus == OrderStatus.success ||
                orderStatus == OrderStatus.applyRefund ||
                orderStatus == OrderStatus.refunding ||
                orderStatus == OrderStatus.refundFail;
    }
    public OrderDetailModel getOneDetail() {
        if (CollUtil.isNotEmpty(orderDetail)) {
            return orderDetail.get(0);
        }
        return null;
    }

    public BigDecimal getPriceDecimal() {
        if (this.getPrice() == null) {
            return BigDecimal.ZERO;
        }
        return BigDecimal.valueOf(this.getPrice() / 100.0);
    }

    @TableField(exist = false)
    private List<OrderDetailModel> orderDetail;
    @TableField(exist = false)
    private PaymentModel paymentModel;

    @TableField(exist = false)
    private String agentId;

    @TableField(exist = false)
    private String agentName;
    @TableField(exist = false)
    private String entityName;
    @TableField(exist = false)
    private String userName;
    @TableField(exist = false)
    private String createdByName;
    @TableField(exist = false)
    private String userMobile;
    @TableField(exist = false)
    private Long money;
    @TableField(exist = false)
    private Object extr;

}
